package com.ycy.temperature.date.net;


import com.ycy.temperature.bean.ActivityBean;
import com.ycy.temperature.bean.BannerBean;
import com.ycy.temperature.bean.DynamicBean;
import com.ycy.temperature.bean.LabelBean;
import com.ycy.temperature.bean.LoginBean;
import com.ycy.temperature.bean.VerificationBean;
import com.ycy.temperature.bean.VipListBean;
import com.ycy.temperature.bean.ＭeBean;
import com.ycy.temperature.date.utils.SharedPreferencesUtils;
import com.ycy.temperature.servicrapi.UserApi;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.File;
import java.util.List;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 访问接口
 */
public class UserNetWorks extends RetrofitUtils {

    protected static final UserApi userApi = RetrofitUtils.getUserApi();

    //登录接口
    public static void getLogin(String mobile, String password, Subscriber<LoginBean> observer) {
        userApi.getLogin(mobile, password).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //注册接口
    public static void getRegister(String usermobile, String verifyCode, String password, String type, Subscriber<VerificationBean> observer) {
        userApi.getRegister(usermobile, verifyCode, password, type).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //获取验证码接口
    public static void getVerification(String phone, String type, Subscriber<VerificationBean> observer) {
        userApi.getVerification(phone, type).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //获取用户资料
    public static void getMe(String phone, Subscriber<VerificationBean> observer) {
        userApi.getMe(phone).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //上传正面身份证
    public static void getPositive(List<File> files, final StringCallback callback) {
        String url = RetrofitUtils.ROOT + "/user/verificationImage.do?token=" + SharedPreferencesUtils.getString("token", "String", "");
        OkHttpUtils.post()
                .url(url)
                .addFile("front", files.get(0).getName(), files.get(0))
                .addParams("phone", "15522422180")
                .build()
                .execute(callback);
    }

    //上传反面身份证
    public static void getOpposite(List<File> files, final StringCallback callback) {
        String url = RetrofitUtils.ROOT + "/user/verificationImage.do?token=" + SharedPreferencesUtils.getString("token", "String", "");
        OkHttpUtils.post()
                .url(url)
                .addFile("reverseSide", files.get(0).getName(), files.get(0))
                .addParams("phone", "15522422180")
                .build()
                .execute(callback);
    }

    //上传头像
    public static void getHeadimage(List<File> files, final StringCallback callback) {
        String url = RetrofitUtils.ROOT + "/user/updateUser.do?token=" + SharedPreferencesUtils.getString("token", "String", "");
        OkHttpUtils.post()
                .url(url)
                .addFile("headImageFile", files.get(0).getName(), files.get(0))
                .build()
                .execute(callback);
    }

    //更新用户信息
    public static void getInformation(String usermobile, String password, String age, String nativeplace, String city, String marriage, String children, String height, String hobby, String monthincome, String weight, String smoke, String drinkwine, String symbolicanimals, String religion, Subscriber<VerificationBean> observer) {
        userApi.getInformation(usermobile, password, age, nativeplace, city, marriage, children, height, hobby, monthincome, weight, smoke, drinkwine, symbolicanimals, religion, "0").subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //获取Banner图片
    public static void getBanner(String phone, Subscriber<BannerBean> observer) {
        userApi.getBanner(phone).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //获取Vip列表
    public static void getVipList(String phone, Subscriber<VipListBean> observer) {
        userApi.getVipList(phone).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //更新用户信息
    public static void getInformation(String nickname, String autograph, Subscriber<VerificationBean> observer) {
        userApi.getInformation(nickname, autograph).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //获取用户资料
    public static void getMeData(String phone, Subscriber<ＭeBean> observer) {
        userApi.getMeData(phone).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //发布活动
    public static void getActivity(String type, String title, String content, String activitytime, String lableid, String releaseaddress, Subscriber<VerificationBean> observer) {
        userApi.getActivity(type, title, content, activitytime, lableid, releaseaddress).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }


    //获取标签
    public static void getLabel(String type, Subscriber<LabelBean> observer) {
        userApi.getLabel(type).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //上传动态图片
    public static void getDynamicimage(List<File> files, final StringCallback callback) {
        String url = RetrofitUtils.ROOT + "/release/releaseCircleImage.do?token=" + SharedPreferencesUtils.getString("token", "String", "");
        OkHttpUtils.post()
                .url(url)
                .addFile("files", files.get(0).getName(), files.get(0))
                .build()
                .execute(callback);
    }

    //发布动态
    public static void getDynamic(String content, String circleimage, String releaseaddress, Subscriber<VerificationBean> observer) {
        userApi.getDynamic(content, circleimage, releaseaddress).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //判断是否可以继续发布动态
    public static void getJudgeRelease(String content, Subscriber<VerificationBean> observer) {
        userApi.getJudgeRelease(content).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //更新用户信息
    public static void getInformation(String height, String monthincome, String weight, String smoke, String drinkwine, String symbolicanimals, String religion, Subscriber<VerificationBean> observer) {
        userApi.getInformation(height, monthincome, weight, smoke, drinkwine, symbolicanimals, religion).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //获取全部动态
    public static void setDynamic(String type, String begin, String page, Subscriber<DynamicBean> observer) {
        userApi.setDynamic(type, begin, page).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //获取个人动态
    public static void setDynamic(String type, String isUser, String begin, String page, Subscriber<DynamicBean> observer) {
        userApi.setDynamic(type, isUser, begin, page).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //给动态点赞
    public static void getFabulous(String createuserid, String circleid, Subscriber<VerificationBean> observer) {
        userApi.getFabulous(createuserid, circleid).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //获取全部活动
    public static void setActivity(String type, String begin, String page, Subscriber<ActivityBean> observer) {
        userApi.setActivity(type, begin, page).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //获取全部活动
    public static void setActivity(String type, String isUser, String begin, String page, Subscriber<ActivityBean> observer) {
        userApi.setActivity(type, isUser, begin, page).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    //发布动态
    public static void getDeleteActivity(String type, String activityOrCircleId, Subscriber<VerificationBean> observer) {
        userApi.getDeleteActivity(type, activityOrCircleId).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
